<template>
  <el-dialog 
    title="配置下拉选项" 
    :visible.sync="dialogVisible"
    width="500px"
    append-to-body
  >
    <div class="select-options-container">
      <div class="options-header">
        <span>选项列表</span>
        <el-button 
          type="text" 
          icon="el-icon-plus" 
          size="mini"
          @click="$emit('add-option')"
        >
          添加选项
        </el-button>
      </div>
      
      <div 
        v-for="(option, index) in options" 
        :key="index"
        class="option-item"
      >
        <el-input 
          v-model="option.label" 
          placeholder="选项文本（如：合格）" 
          size="mini"
          class="option-input"
          maxlength="20"
          show-word-limit
        ></el-input>
        <el-input 
          v-model="option.value" 
          placeholder="选项值（如：qualified）" 
          size="mini"
          class="option-input"
          maxlength="50"
        ></el-input>
        <el-button 
          type="danger" 
          icon="el-icon-delete" 
          size="mini"
          @click="$emit('remove-option', index)"
          circle
        ></el-button>
      </div>

      <div v-if="options.length === 0" class="empty-options">
        <i class="el-icon-tickets"></i>
        <p>暂无选项，请添加选项</p>
      </div>
    </div>

    <div slot="footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="$emit('save')">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'SelectOptionsDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    options: {
      type: Array,
      required: true
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(value) {
        this.$emit('update:visible', value);
      }
    }
  }
};
</script>

<style scoped>
.select-options-container {
  max-height: 400px;
  overflow-y: auto;
}

.options-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ebeef5;
  font-weight: 600;
  color: #303133;
}

.option-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 4px;
}

.option-input {
  flex: 1;
}

.empty-options {
  text-align: center;
  padding: 40px 20px;
  color: #909399;
}

.empty-options i {
  font-size: 36px;
  margin-bottom: 12px;
  color: #c0c4cc;
}

.empty-options p {
  margin: 0;
  font-size: 14px;
}
</style>